﻿using HBKY.Shop.Common;
using HBKY.Shop.Common.Extension;
using HBKY.Shop.Model.Enum;

namespace HBKY.Shop.Extensions.AuthHelper.Policys
{
    /// <summary>
    /// 中间件异常
    /// </summary>
    public class ApiResponse
    {
        public int Status { get; set; } = 404;
        public string Value { get; set; } = "No Found";
        public ResponseMessage<string> responseMessage { get; set; } = new ResponseMessage<string>() { };

        public ApiResponse(StatusCodeEnum apiCode, string msg = null)
        {
            switch (apiCode)
            {
                case StatusCodeEnum.Status401Unauthorized:
                    {
                        Status = StatusCodeEnum.Status401Unauthorized.Key();
                        Value = "很抱歉，您无权访问该接口，请确保已经登录!";
                    }
                    break;
                case StatusCodeEnum.Status403Unauthorized:
                    {
                        Status = StatusCodeEnum.Status403Unauthorized.Key();
                        Value = "很抱歉，您的访问权限等级不够，联系管理员!";
                    }
                    break;
                case StatusCodeEnum.Status500InternalServerError:
                    {
                        Status = StatusCodeEnum.Status500InternalServerError.Key();
                        Value = msg;
                    }
                    break;
            }

            responseMessage = new ResponseMessage<string>()
            {
                Code = Status,
                Message = Value,
                Success = false
            };
        }
    }
  
}
